package com.flux.store

import com.flux.action.RxStoreChange
import com.flux.dispatcher.Dispatcher
import com.flux.dispatcher.RxActionDispatch

/**
 * This class must be extended by each store of the app in order to recieve the actions dispatched
 * by the
 */
abstract class RxStore(private val dispatcher: Dispatcher) : RxActionDispatch {

    fun register() {
        dispatcher.subscribeRxStore(this)
    }

    fun unregister() {
        dispatcher.unsubscribeRxStore(this)
    }

    protected fun postChange(change: RxStoreChange) {
        dispatcher.postRxStoreChange(change)
    }
}